package cn.zooz.service.sys.impl;

import cn.zooz.service.o.vo.SysUserListVo;
import cn.zooz.entity.SysUser;
import cn.zooz.manager.sys.SysUserManager;
import cn.zooz.service.sys.SysLoginService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by Bradish7Y on 2017/9/23.
 */
@Service
public class SysLoginServiceImpl implements SysLoginService {

    @Resource
    private SysUserManager sysUserManager;

    @Override
    public SysUserListVo listAllSysUser(Page<SysUser> page) {
        //查询所有记录
        Page<SysUser> userPage = sysUserManager.selectPage(page, new EntityWrapper<>());
        Page<SysUserListVo> sysUserListVoPage =  new Page<>();

        //复制bean
        BeanUtils.copyProperties(userPage, sysUserListVoPage);

        SysUserListVo ret = new SysUserListVo();
        ret.setPage(sysUserListVoPage);

        return ret;
    }

    @Override
    public boolean register(SysUser sysUser) {
        return sysUserManager.insert(sysUser);
    }

    @Override
    public boolean delete(Long userId) {
        return sysUserManager.delete(new EntityWrapper<SysUser>().eq("user_id", userId));
    }

    @Override
    public boolean update(SysUser sysUser) {
        return sysUserManager.update(sysUser, new EntityWrapper<SysUser>().eq("username", sysUser.getUsername()));
    }
}
